﻿using System.Collections.Generic;
using Lari.Services.ViewModel;

namespace Lari.Services.Data
{
    public static class Extension
    {

        #region Gender
        public static GenderModel ConvertToViewModel(this Gender gender)
        {
            return new GenderModel { Code = gender.Code.Trim(), Name = gender.Name.Trim(), IsDefault = gender.IsDefault };
        }

        public static Gender ConvertToEntityModel(this GenderModel gender)
        {
            return new Gender { Code = gender.Code.Trim(), Name = gender.Name.Trim(), IsDefault = gender.IsDefault };
        } 
        #endregion

        #region Country
        public static CountryModal ConvertToViewModel(this Country country)
        {
            return new CountryModal { Code = country.Code.Trim(), Name = country.Name.Trim(), IsDefault = country.IsDefault };
        }

        public static Country ConvertToEntityModel(this CountryModal country)
        {

            return new Country { Code = country.Code.Trim(), Name = country.Name.Trim(), IsDefault = country.IsDefault };
        } 
        #endregion

        #region state
        public static StateModel ConvertToViewModel(this State state)
        {
            return new StateModel { Code = state.Code.Trim(), Name = state.Name.Trim(), IsDefault = state.IsDefault };
        }

        public static State ConvertToEntityModel(this StateModel state)
        {

            return new State { Code = state.Code.Trim(), Name = state.Name.Trim(), IsDefault = state.IsDefault };
        } 
        #endregion

        #region religion
        public static ReligionModel ConvertToViewModel(this Religion reli)
        {
            return new ReligionModel { Code = reli.Code.Trim(), Name = reli.Name.Trim(), IsDefault = reli.IsDefault };
        }

        public static Religion ConvertToEntityModel(this ReligionModel religion)
        {

            return new Religion { Code = religion.Code.Trim(), Name = religion.Name.Trim(), IsDefault = religion.IsDefault };
        }
        #endregion

        #region Maritaul ststus
        public static MaritalStatusModel ConvertToViewModel(this MaritalStatus marital)
        {
            return new MaritalStatusModel { Code = marital.Code.Trim(), Name = marital.Name.Trim(), IsDefault = marital.IsDefault };
        }

        public static MaritalStatus ConvertToEntityModel(this MaritalStatusModel maritalStatus)
        {

            return new MaritalStatus { Code = maritalStatus.Code.Trim(), Name = maritalStatus.Name.Trim(), IsDefault = maritalStatus.IsDefault };
        }
        #endregion

        #region EmployeeType
        public static EmployeeTypeModel ConvertToViewModel(this EmployeeType employeeType)
        {
            return new EmployeeTypeModel { Name = employeeType.Name.Trim(), Id = employeeType.ID };
        }

        public static EmployeeType ConvertToEntityModel(this EmployeeTypeModel employeeTypeModel)
        {

            return new EmployeeType { Name = employeeTypeModel.Name.Trim(), ID = employeeTypeModel.Id };
        } 
        #endregion

        #region Titles
        public static TitleModel ConvertToViewModel(this Title title)
        {
            return new TitleModel { Name = title.Name.Trim(), ID = title.ID };
        }

        public static Title ConvertToEntityModel(this TitleModel titleModel)
        {

            return new Title { Name = titleModel.Name.Trim(), ID = titleModel.ID };
        } 


        #endregion

        #region Bloodgroup
        public static BloodgroupModel ConvertToViewModel(this Bloodgroup group)
        {
            return new BloodgroupModel { Name = group.Name.Trim(), Id = group.Id };
        }

        public static Bloodgroup ConvertToEntityModel(this BloodgroupModel group)
        {

            return new Bloodgroup { Name = group.Name.Trim(),Id = group.Id };
        }
        #endregion

        #region Designation
        public static DesignationModel ConvertToViewModel(this Designation dessignation)
        {
            return new DesignationModel { Name = dessignation.Name.Trim(), Id = dessignation.Id };
        }

        public static Designation ConvertToEntityModel(this DesignationModel dessignation)
        {

            return new Designation { Name = dessignation.Name.Trim(), Id = dessignation.Id };
        }

        #endregion 

        #region Department 
        public static DepartmentModel ConvertToViewModel(this Department department)
        {
            var designationCount = department.DepDesignationMappings != null ?
                department.DepDesignationMappings.Count : 0;




            return new DepartmentModel { Name = department.Name.Trim(), Id = department.Id,DesignationCount = designationCount };
        }
        
        public static Department ConvertToEntityModel(this DepartmentModel department)
        {

            return new Department { Name = department.Name.Trim(), Id = department.Id };
        }
        public static DepartmentDesignationModel ConvertToDesignationMappingModel(this Department dep)
        {
            var model = new DepartmentDesignationModel { DepartmentId = dep.Id, DeapartmentName = dep.Name };
            if (dep.DepDesignationMappings != null && dep.DepDesignationMappings.Count > 0)
            {
                model.Designations = new List<DepDesignationMappingModel>();
                foreach (var design in dep.DepDesignationMappings)
                {
                    model.Designations.Add(new DepDesignationMappingModel { DesignationId = design.DesignationID, DesignationName = design.Designation.Name, IsMapped = true });
                }
            }
            return model;

        }
        
        #endregion

        #region Specialization 
/*
		 public static SpecializationModel ConvertToViewModel(this Specialization spec)
        {
            return new SpecializationModel { Name = spec.Name.Trim(),ID= spec.ID, DepartmentID = spec.DepartmentID};
        }
*/

/*
        public static Specialization ConvertToEntityModel(this SpecializationModel spec)
        {

           return new Specialization { Name = spec.Name.Trim(),ID= spec.ID, DepartmentID = spec.DepartmentID};
        } 
*/

        #endregion

        public static Employee ConvertToEntityModel (this EmployeeModel view)
        {
            var model = new Employee
                            {
                                ID = view.ID,
                                Title = view.Title,
                                FirstName = view.FirstName,
                                Middlename = view.Middlename,
                                LastName = view.LastName,
                                DOB = view.DOB,
                                Age = view.Age,
                                IsDOBCulculated = view.IsDOBCulculated,
                                GenderCode = view.GenderCode,
                                DesignationId = view.DesignationId,
                                DepartmentId = view.DepartmentId,
                                Location = view.Location,
                                EmployeeType = view.EmployeeType,
                                MaritalStatusCode = view.MaritalStatusCode,
                                BloodGpId = view.BloodGpId,
                                ReligionCode = view.ReligionCode,
                                NationalityCode = view.NationalityCode,
                                HomeAddress = view.HomeAddress,
                                HomeCity = view.HomeCity,
                                HomeStateCode = view.HomeStateCode,
                                HomeStateOther = view.HomeStateOther,
                                HomeCountryCode = view.HomeCountryCode,
                                HomePinCode = view.HomePinCode,
                                HomePhone = view.HomePhone,
                                WorkAddress = view.WorkAddress,
                                WorkCity = view.WorkCity,
                                WorkStateCode = view.WorkStateCode,
                                WorkStateOther = view.WorkStateOther,
                                WorkCountryCode = view.WorkCountryCode,
                                WorkPinCode = view.WorkPinCode,
                                WorkPhone = view.WorkPhone,
                                Mobile = view.Mobile,
                                Email = view.Email,
                                IsConsultant = view.IsConsultant,
                                Active = view.Active,
                                Photograph = view.Photograph,
                                
                            };

            return model;
        }

        public static EmployeeModel ConvertToViewModel(this Employee model)
        {
            var view = new EmployeeModel
                           {
                               ID = model.ID,
                               Title = model.Title,
                               FirstName = model.FirstName,
                               Middlename = model.Middlename,
                               LastName = model.LastName,
                               DOB = model.DOB,
                               Age = model.Age,
                               IsDOBCulculated = model.IsDOBCulculated,
                               GenderCode = model.GenderCode,
                               DesignationId = model.DesignationId,
                               DepartmentId = model.DepartmentId,
                               Location = model.Location,
                               EmployeeType = model.EmployeeType,
                               MaritalStatusCode = model.MaritalStatusCode,
                               BloodGpId = model.BloodGpId,
                               ReligionCode = model.ReligionCode,
                               NationalityCode = model.NationalityCode,
                               HomeAddress = model.HomeAddress,
                               HomeCity = model.HomeCity,
                               HomeStateCode = model.HomeStateCode,
                               HomeStateOther = model.HomeStateOther,
                               HomeCountryCode = model.HomeCountryCode,
                               HomePinCode = model.HomePinCode,
                               HomePhone = model.HomePhone,
                               WorkAddress = model.WorkAddress,
                               WorkCity = model.WorkCity,
                               WorkStateCode = model.WorkStateCode,
                               WorkStateOther = model.WorkStateOther,
                               WorkCountryCode = model.WorkCountryCode,
                               WorkPinCode = model.WorkPinCode,
                               WorkPhone = model.WorkPhone,
                               Mobile = model.Mobile,
                               Email = model.Email,
                               IsConsultant = model.IsConsultant,
                               Active = model.Active,
                               Photograph = model.Photograph
                           };

            
            return view;
        }

        public static void ModeltoModelMapping(this Employee emp , Employee mapper)
        {
            emp.ID = mapper.ID;
            emp.Title = mapper.Title;
            emp.FirstName = mapper.FirstName;
            emp.Middlename = mapper.Middlename;
            emp.LastName = mapper.LastName;
            emp.DOB = mapper.DOB;
            emp.Age = mapper.Age;
            emp.IsDOBCulculated = mapper.IsDOBCulculated;
            emp.GenderCode = mapper.GenderCode;
            emp.DesignationId = mapper.DesignationId;
            emp.DepartmentId = mapper.DepartmentId;
            emp.Location = mapper.Location;
            emp.EmployeeType = mapper.EmployeeType;
            emp.MaritalStatusCode = mapper.MaritalStatusCode;
            emp.BloodGpId = mapper.BloodGpId;
            emp.ReligionCode = mapper.ReligionCode;
            emp.NationalityCode = mapper.NationalityCode;
            emp.HomeAddress = mapper.HomeAddress;
            emp.HomeCity = mapper.HomeCity;
            emp.HomeStateCode = mapper.HomeStateCode;
            emp.HomeStateOther = mapper.HomeStateOther;
            emp.HomeCountryCode = mapper.HomeCountryCode;
            emp.HomePinCode = mapper.HomePinCode;
            emp.HomePhone = mapper.HomePhone;
            emp.WorkAddress = mapper.WorkAddress;
            emp.WorkCity = mapper.WorkCity;
            emp.WorkStateCode = mapper.WorkStateCode;
            emp.WorkStateOther = mapper.WorkStateOther;
            emp.WorkCountryCode = mapper.WorkCountryCode;
            emp.WorkPinCode = mapper.WorkPinCode;
            emp.WorkPhone = mapper.WorkPhone;
            emp.Mobile = mapper.Mobile;
            emp.Email = mapper.Email;
            emp.IsConsultant = mapper.IsConsultant;
            emp.Active = mapper.Active;
            emp.Photograph = mapper.Photograph;

        }

        public static UserModel ConvertToViewModel(this User model)
        {
            var view = new UserModel {UserId = model.UserId,RoleId = model.RoleID};

            return view;
        } 
    }
}
